import threading
import time
def add_a(count,l):
    global num
    print('a是'+str(num))
    for i in range(count):
        l.acquire()
        num += 1
        l.release()
    print('a最终是'+str(num))
def add_b(count,l):
    global num
    print('b是'+str(num))
    for i in range(count):
        l.acquire()
        num += 1
        l.release()
    print('b最终是'+str(num))
def main():
    l = threading.Lock()
    t1 = threading.Thread(target=add_a, args=(1000000,l))
    t2 = threading.Thread(target=add_b, args=(1000000,l))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    time.sleep(1)
    print(num)
if __name__ == '__main__':
    num = 0
    main()